﻿// ———————————————————————–
// <copyright file=""RouterRule".cs" company="The MITRE Corporation">
//    Copyright (c) 2014 The MITRE Corporation. All rights reserved.
//    Licensed under the Apache License, Version 2.0 (the "License");
//    you may not use this file except in compliance with the License.
//    You may obtain a copy of the License at
//    http://www.apache.org/licenses/LICENSE-2.0
//    Unless required by applicable law or agreed to in writing, software
//    distributed under the License is distributed on an "AS IS" BASIS,
//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//    See the License for the specific language governing permissions and
//    limitations under the License.
// </copyright>
// ———————————————————————–
/////////////////////////////////////////////////////////////////////////////////////////////////
// RouterRule.cs - XML Serializer for Router Rule 
// Project: EDXLSharp_AWSRouter - ICNETSerializers
//
// Language:    C#, .NET 4.0
// Platform:    Windows 7, VS 2013
// Author:      Brian Wilkins The MITRE Corporation
/////////////////////////////////////////////////////////////////////////////////////////////////

// Copyright (c) 2014 The MITRE Corporation. All rights reserved.
//
// NOTICE
// This software was produced for the U. S. Government
// under Contract No. FA8721-09-C-0001, and is
// subject to the Rights in Noncommercial Computer Software
// and Noncommercial Computer Software Documentation Clause
// (DFARS) 252.227-7014 (JUN 1995)

using Amazon.DynamoDBv2.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using System.Xml.Serialization;

[assembly: log4net.Config.XmlConfigurator(Watch = true)]

namespace ICNETSerializers
{
  /// <summary>
  /// XML Serializer for Router Rules Value List source
  /// Represents name of DE ValueList element
  /// </summary>
  [Serializable]
  public enum ValueListSource
  {
    [XmlEnum("senderRole")]
    senderRole,
    [XmlEnum("recipientRole")]
    recipientRole,
    [XmlEnum("keyword")]
    keyword,
    [XmlEnum("contentKeyword")]
    contentKeyword,
    [XmlEnum("originatorRole")]
    originatorRole,
    [XmlEnum("consumerRole")]
    consumerRole
  }

  [Serializable]
  [XmlRoot("RouterRules", Namespace="mitre:icnet:aws:1.0")]
  public class RouterRules
  {

    #region Public Delegates/Events

    #endregion Public Delegates/Events

    #region Private Member Variables
    List<RouterRule> mRules;
    private static readonly log4net.ILog Log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

    #endregion Private Member Variables

    #region Constructors

    public RouterRules()
    {
      mRules = new List<RouterRule>();
    }
    #endregion Constructors

    #region Public Accessors
    /// <summary>
    /// Gets or sets the Router Rule destination Feed Hashes
    /// </summary>
    [XmlElement("routerRule")]
    public List<RouterRule> Rules
    {
      get { return mRules; }
      set { mRules = value; }
    }
    #endregion Public Accessors

    #region Public Member Functions

    #endregion Public Member Functions

    #region Protected Member Functions

    #endregion Protected Member Functions

    #region Private Member Functions

    #endregion Private Member Functions
                
  }

  [Serializable]
  public class RouterRule
  {
    #region Public Delegates/Events

    #endregion Public Delegates/Events

    #region Private Member Variables

    private string mValueListUrn;
    private string mValue;
    private ValueListSource mKind;
    List<FeedHash> mHashes;
    List<string> mFederationUris;

    #endregion Private Member Variables

    #region Constructors

    #endregion Constructors

    #region Public Accessors
    /// <summary>
    /// Gets or sets the Router Rule ValueList urn
    /// </summary>
    [XmlElement("valueListUrn")]
    public string ValueListUrn
    {
      get { return mValueListUrn; }
      set { mValueListUrn = value; }
    }

    /// <summary>
    /// Gets or sets the Router Rule ValueList value
    /// </summary>
    [XmlElement("value")]
    public string Value
    {
      get { return mValue; }
      set { mValue = value; }
    }

    /// <summary>
    /// Gets or sets the Router Rule ValueList kind
    /// </summary>
    [XmlElement("kind")]
    public ValueListSource Kind
    {
      get { return mKind; }
      set { mKind = value; }
    }

    /// <summary>
    /// Gets or sets the Router Rule destination Feed Hashes
    /// </summary>
    [XmlArray("feedHashes")]
    [XmlArrayItem("feedHash")]
    public List<FeedHash> FeedHashes
    {
      get { return mHashes; }
      set { mHashes = value; }
    }

    [XmlIgnore]
    public bool FeedHashesSpecified
    {
      get
      {
        bool hasValues = mHashes != null && mHashes.Count > 0;
        return hasValues;
      }
      set { }
    }

    /// <summary>
    /// Gets or sets the Router Rule Federation URIs
    /// </summary>
    [XmlArray("federationUris")]
    [XmlArrayItem("federationUri")]
    public List<string> FederationURIs
    {
      get { return mFederationUris; }
      set { mFederationUris = value; }
    }

    [XmlIgnore]
    public bool FederationURIsSpecified
    {
      get
      {
        bool hasValues = mFederationUris != null && mFederationUris.Count > 0;
        return hasValues;
      }
      set { }
    }
    #endregion Public Accessors

    #region Public Member Functions

    #endregion Public Member Functions

    #region Protected Member Functions

    #endregion Protected Member Functions

    #region Private Member Functions

    #endregion Private Member Functions
                
  }

  /// <summary>
  /// XML Serializer for Router Rules table feed hash field
  /// </summary>
  [Serializable]
  public class FeedHash : IComparable
  {

    #region Public Delegates/Events

    #endregion Public Delegates/Events

    #region Private Member Variables

    private string mValueListUrn;

    private string mValue;

    #endregion Private Member Variables

    #region Constructors

    #endregion Constructors

    #region Public Accessors

    /// <summary>
    /// Gets or sets ValueList urn
    /// </summary>
    [XmlElement("valueListUrn")]
    public string ValueListUrn
    {
      get { return mValueListUrn; }
      set { mValueListUrn = value; }
    }

    /// <summary>
    /// Gets or sets a ValueList value
    /// </summary>
    [XmlElement("value")]
    public string Value
    {
      get {return mValue;}
      set { mValue = value; }
    }
    #endregion Public Accessors

    #region Public Member Functions

    #endregion Public Member Functions

    #region Protected Member Functions

    #endregion Protected Member Functions

    #region Private Member Functions

    #endregion Private Member Functions


    public int CompareTo(object obj)
    {
      if (obj == null) return 1;

      FeedHash otherFH = obj as FeedHash;
      if (otherFH != null)
      {
        return String.Format("{0}::{1}", this.ValueListUrn, this.Value).CompareTo(String.Format("{0}::{1}", otherFH.ValueListUrn, otherFH.Value));
      }
      else
      {
        throw new ArgumentException("Object is not a FeedHash");
      }
    }
  }

}
